diff --git a/src/Console/OptionsMakeCommand.php b/src/Console/OptionsMakeCommand.php index c56043a..315b48c 100644 --- a/src/Console/OptionsMakeCommand.php +++ b/src/Console/OptionsMakeCommand.php @@ -11,6 +11,7 @@ class OptionsMakeCommand extends MakeCommand */ protected $signature = 'acf:options {name* : The name of the options page} {--full : Scaffold an options page that contains the complete configuration.} + {--localize : Localize the options page name and title} {--force : Overwrite any existing files}'; /** @@ -45,6 +46,10 @@ protected function getStub() return $this->resolveStub('options.full'); } + if ($this->option('localize')) { + return $this->resolveStub('options.localized'); + } + return $this->resolveStub('options'); } } diff --git a/src/Console/StubPublishCommand.php b/src/Console/StubPublishCommand.php index f252ad6..33c6bfe 100644 --- a/src/Console/StubPublishCommand.php +++ b/src/Console/StubPublishCommand.php @@ -33,6 +33,7 @@ class StubPublishCommand extends Command 'block.localized.stub', 'block.stub', 'field.stub', + 'options.localized.stub', 'options.full.stub', 'options.stub', 'partial.stub', diff --git a/src/Console/stubs/options.localized.stub b/src/Console/stubs/options.localized.stub new file mode 100644 index 0000000..15bb853 --- /dev/null +++ b/src/Console/stubs/options.localized.stub @@ -0,0 +1,47 @@ +addRepeater('items') + ->addText('item') + ->endRepeater(); + + return $fields->build(); + } +} diff --git a/src/Console/stubs/options.stub b/src/Console/stubs/options.stub index e80f53c..215e98a 100644 --- a/src/Console/stubs/options.stub +++ b/src/Console/stubs/options.stub @@ -21,6 +21,13 @@ class DummyClass extends Field */ public $title = 'DummyTitle | Options'; + /** + * The option page menu position. + * + * @var int + */ + public $position = PHP_INT_MAX; + /** * The option page field group. */ diff --git a/src/Options.php b/src/Options.php index 394049f..2afd7fd 100644 --- a/src/Options.php +++ b/src/Options.php @@ -91,6 +91,22 @@ abstract class Options extends Composer */ public $settings = []; + /** + * Retrieve the option page menu name. + */ + public function getName(): string + { + return $this->name; + } + + /** + * Retrieve the option page document title. + */ + public function getTitle(): string + { + return $this->title; + } + /** * Localized text displayed on the submit button. * @@ -118,16 +134,16 @@ public function updatedMessage() */ public function compose() { - if (empty($this->name)) { - return; - } + if (blank($this->getName())) { + return null; + } if (empty($this->slug)) { - $this->slug = Str::slug($this->name); + $this->slug = Str::slug($this->getName()); } - if (empty($this->title)) { - $this->title = $this->name; + if (blank($this->getTitle())) { + $this->title = $this->getName(); } if (! Arr::has($this->fields, 'location.0.0')) { @@ -145,9 +161,9 @@ public function compose() acf_add_options_page( array_merge([ - 'menu_title' => $this->name, + 'menu_title' => $this->getName(), 'menu_slug' => $this->slug, - 'page_title' => $this->title, + 'page_title' => $this->getTitle(), 'capability' => $this->capability, 'position' => $this->position, 'parent_slug' => $this->parent,